from django.db import models
from django.contrib.auth.models import User


class WasteClassification(models.Model):
    """垃圾分类信息表 - 各城市的垃圾分类标准数据库"""
    CITY_CHOICES = [
        ('北京', '北京'), ('上海', '上海'), ('广州', '广州'), ('深圳', '深圳'),
        ('杭州', '杭州'), ('南京', '南京'), ('武汉', '武汉'), ('成都', '成都'),
        ('重庆', '重庆'), ('西安', '西安'), ('天津', '天津'), ('苏州', '苏州'),
        ('其他', '其他')
    ]
    CATEGORY_CHOICES = [
        ('有害垃圾', '有害垃圾'), ('可回收物', '可回收物'), ('厨余垃圾', '厨余垃圾'), ('其他垃圾', '其他垃圾')
    ]
    waste_id = models.AutoField(primary_key=True, verbose_name='词条唯一ID', db_comment='词条唯一ID')
    item_name = models.CharField(max_length=100, verbose_name='垃圾名称', db_comment='垃圾名称')
    category = models.CharField(max_length=50, choices=CATEGORY_CHOICES, verbose_name='分类(有害垃圾等)', db_comment='分类(有害垃圾等)')
    city = models.CharField(max_length=50, choices=CITY_CHOICES, verbose_name='适用城市', db_comment='适用城市')
    description = models.TextField(null=True, blank=True, verbose_name='处理建议', db_comment='处理建议')

    class Meta:
        db_table = 'xiangsu_waste_classification'
        db_table_comment = '垃圾分类信息表-各城市的垃圾分类标准数据库'
        verbose_name = '垃圾分类信息'
        verbose_name_plural = '垃圾分类信息'

    def __str__(self):
        return f'{self.item_name}({self.city})'


class UserSubmission(models.Model):
    """用户纠错提交表 - 用户贡献的垃圾分类词条"""
    STATUS_CHOICES = [
        ('pending', '待审核'),
        ('approved', '已采纳'),
    ]

    submission_id = models.AutoField(primary_key=True, verbose_name='提交唯一ID', db_comment='提交唯一ID')
    user = models.ForeignKey('auth.User', on_delete=models.CASCADE, db_column='user_id', verbose_name='提交用户', db_comment='提交用户', null=True, blank=True)
    term = models.CharField(max_length=100, verbose_name='用户提交词条', db_comment='用户提交词条')
    ai_temp_answer = models.CharField(max_length=255, null=True, blank=True, verbose_name='AI临时答案', db_comment='AI临时答案')
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending', verbose_name='审核状态', db_comment='审核状态')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='提交时间', db_comment='提交时间')

    class Meta:
        db_table = 'xiangsu_user_submissions'
        db_table_comment = '用户纠错提交表-用户贡献的垃圾分类词条'
        verbose_name = '用户纠错提交'
        verbose_name_plural = '用户纠错提交'
        ordering = ['-created_at']

    def __str__(self):
        return f'用户{self.user.id}提交:{self.term}'
